home *** CD-ROM | disk | FTP | other *** search
- PROGRAM bbmfix;
-
- (*===========================================================================*)
- (* Fix message file *)
- (* *)
- (* Copyright 1988 by H. Roy Engehausen. All rights reserved. *)
- (* This software may be freely distributed and used, but it may not *)
- (* under any circumstances be sold by anyone other than the author. *)
- (* It may be distributed by a commercial company as long as it is *)
- (* for no cost. *)
- (* *)
- (* Permission is explicity granted to use this code as a model for *)
- (* other programs as long as they carry this copyright notice and the *)
- (* imbedded copyright constants *)
- (* *)
- (*===========================================================================*)
-
- {$R+} {Range checking on}
- {$B-} {Boolean complete evaluation off}
- {$S+} {Stack checking on}
- {$I+} {I/O checking on}
- {$V+} {String var checks}
- {$N-} {No numeric coprocessor}
-
- USES
- CRT,
- bbdummy;
-
- (*===========================================================================*)
- (* Main program begins here *)
- (*===========================================================================*)
-
- VAR
- dis_p : msg_d_ptr;
- e_file : FILE OF msg_block;
- first_time : BOOLEAN;
- fix_file : FILE OF msg_block;
- i : WORD;
- i_name : STRING;
- li : LONGINT;
- k : WORD;
- msg_buffer : msg_block;
- msg_file : FILE OF msg_block;
- msg2_buffer : msg_block;
- next_msg_no : WORD;
- no_blk : WORD;
- no_blk_max : WORD;
- no_blk_tell : WORD;
- o_name : STRING;
- rename_it : BOOLEAN;
- x_switch : BOOLEAN;
-
- LABEL
- loop;
-
- FUNCTION yn : BOOLEAN;
- VAR
- c : CHAR;
- x : STRING;
-
- BEGIN;
-
- IF x_switch THEN
- BEGIN;
- yn := TRUE;
- EXIT;
- END;
-
- WHILE TRUE DO
- BEGIN;
- WRITELN('Enter Y or N or X (Yes and dont ask anymore)');
- READLN(x);
- IF LENGTH(x) <> 1 THEN
- WRITELN('Wrong length')
- ELSE
- BEGIN;
- c := UPCASE(x[1]);
- IF c = 'X' THEN
- BEGIN;
- x_switch := TRUE;
- yn := TRUE;
- EXIT;
- END;
- IF (c = 'Y') OR (c = 'N') THEN
- BEGIN;
- yn := c = 'Y';
- EXIT;
- END;
- WRITELN('Answer not Y or N');
- END;
-
- END;
- END;
-
- FUNCTION deleteme : BOOLEAN;
- BEGIN;
- WRITELN('Delete this record?');
- deleteme := yn;
- END;
-
- (*===========================================================================*)
- (* Main program begins here *)
- (*===========================================================================*)
-
- BEGIN;
-
- dis_p := @msg2_buffer;
-
- x_switch := FALSE;
-
- i_name := PARAMSTR(1);
- o_name := PARAMSTR(2);
-
- IF i_name = '' THEN
- i_name := 'MSG.BB';
-
- IF o_name = '' THEN
- BEGIN;
- o_name := 'MSG.OK';
- rename_it := TRUE;
- END
- ELSE
- rename_it := FALSE;
-
- (*-----------------------------------------------------------------------*)
- (* Open msg file for read *)
- (*-----------------------------------------------------------------------*)
-
- ASSIGN(msg_file, i_name);
- {$I-}
- RESET(msg_file);
- {$I+}
- i := IORESULT;
-
- (*-----------------------------------------------------------------------*)
- (* Check for open OK *)
- (*-----------------------------------------------------------------------*)
-
- IF (i <> 0) AND (i <> 2) THEN
- BEGIN;
- WRITELN('Unable to open ', opt_block.msg_file_name);
- WRITELN('DOS Error # ', i);
- END;
-
- (*-----------------------------------------------------------------------*)
- (* File doesn't exist. *)
- (*-----------------------------------------------------------------------*)
-
- IF i <> 0 THEN
- BEGIN;
-
- WRITELN('File does not exist');
- HALT;
-
- END;
-
- (*-----------------------------------------------------------------------*)
- (* Open msg file for write *)
- (*-----------------------------------------------------------------------*)
-
- ASSIGN(fix_file, o_name);
- REWRITE(fix_file);
-
- (*-----------------------------------------------------------------------*)
- (* Check the version of the file *)
- (*-----------------------------------------------------------------------*)
-
- READ(msg_file, msg_buffer);
- i := msg_buffer.msg_number;
- IF i <> sys_version THEN
- BEGIN;
- WRITELN('Wanted version ', sys_version, ' msg file');
- WRITELN('Got version ', i, ' msg file');
- HALT;
- END;
-
- (*-----------------------------------------------------------------------*)
- (* Write the version header *)
- (*-----------------------------------------------------------------------*)
-
- WRITE(fix_file, msg_buffer);
-
- (*-----------------------------------------------------------------------*)
- (* Read in the message file *)
- (*-----------------------------------------------------------------------*)
-
- next_msg_no := 1;
- first_time := TRUE;
-
- no_blk := 0;
- no_blk_tell := 0;
- no_blk_max := FILESIZE(msg_file) - 1;
-
- loop:
- WHILE no_blk < no_blk_max DO
- BEGIN;
-
- li := SIZEOF(msg_buffer);
- li := li * no_blk;
-
- i := no_blk DIV 10;
- IF i <> no_blk_tell THEN
- BEGIN;
- no_blk_tell := i;
- WRITELN('Processing record # ', no_blk);
- END;
-
- (*-------------------------------------------------------------------*)
- (* Read in the next record *)
- (*-------------------------------------------------------------------*)
-
- INC(no_blk);
-
- READ(msg_file, msg_buffer);
-
- (*-------------------------------------------------------------------*)
- (* Validate number *)
- (*-------------------------------------------------------------------*)
-
- IF first_time THEN
- BEGIN;
- WITH msg_buffer DO
- next_msg_no := msg_number - 1;
- first_time := FALSE;
- END;
-
- WITH msg_buffer DO
- IF next_msg_no > msg_number THEN
- BEGIN;
- WRITELN('**** Warning -- MSG file out of sequence');
- WRITELN('Record number # ', no_blk, '(', li,
- ') is msg # ', msg_number);
- WRITELN('High number # ', next_msg_no);
- IF deleteme THEN GOTO loop;
- END
- ELSE
- BEGIN;
- IF (next_msg_no + 100) < msg_number THEN
- BEGIN;
- WRITELN('**** Warning -- MSG file gap detected');
- WRITELN('Record number # ', no_blk, '(', li,
- ') is msg # ', msg_number);
- WRITELN('High number # ', next_msg_no);
- IF deleteme THEN GOTO loop;
- END;
-
- next_msg_no := msg_number + 1;
-
- END;
-
- (*-------------------------------------------------------------------*)
- (* Validate sizes *)
- (*-------------------------------------------------------------------*)
-
- WITH msg_buffer DO
- BEGIN;
-
- IF LENGTH(msg_to) >= SIZEOF(msg_to) THEN
- BEGIN;
- WRITELN('**** Warning -- MSG_TO size error');
- WRITELN('Record number # ', no_blk, '(', li,
- ') is msg # ', msg_number);
- WRITELN('MSG_TO = ', msg_to);
- WRITELN('L = ', LENGTH(msg_to), ' -- MAX = ', SIZEOF(msg_to));
- IF deleteme THEN GOTO loop;
- END;
-
- IF LENGTH(msg_to_at) >= SIZEOF(msg_to_at) THEN
- BEGIN;
- WRITELN('**** Warning -- MSG_TO_AT size error');
- WRITELN('Record number # ', no_blk, '(', li,
- ') is msg # ', msg_number);
- WRITELN('MSG_TO_AT = ', msg_to_at);
- WRITELN('L = ', LENGTH(msg_to_at),
- ' -- MAX = ', SIZEOF(msg_to_at));
- IF deleteme THEN GOTO loop;
- END;
-
- IF LENGTH(msg_from) >= SIZEOF(msg_from) THEN
- BEGIN;
- WRITELN('**** Warning -- MSG_FROM size error');
- WRITELN('Record number # ', no_blk, '(', li,
- ') is msg # ', msg_number);
- WRITELN('MSG_FROM = ', msg_from);
- WRITELN('L = ', LENGTH(msg_from),
- ' -- MAX = ', SIZEOF(msg_from));
- IF deleteme THEN GOTO loop;
- END;
-
- IF LENGTH(msg_from_at) >= SIZEOF(msg_from_at) THEN
- BEGIN;
- WRITELN('**** Warning -- MSG_FROM_AT size error');
- WRITELN('Record number # ', no_blk, '(', li,
- ') is msg # ', msg_number);
- WRITELN('MSG_FROM = ', msg_from_at);
- WRITELN('L = ', LENGTH(msg_from_at),
- ' -- MAX = ', SIZEOF(msg_from_at));
- IF deleteme THEN GOTO loop;
- END;
-
- IF LENGTH(msg_bid) >= SIZEOF(msg_bid) THEN
- BEGIN;
- WRITELN('**** Warning -- MSG_BID size error');
- WRITELN('Record number # ', no_blk, '(', li,
- ') is msg # ', msg_number);
- WRITELN('MSG_BID = ', msg_bid);
- WRITELN('L = ', LENGTH(msg_bid),
- ' -- MAX = ', SIZEOF(msg_bid));
- IF deleteme THEN GOTO loop;
- END;
-
- IF LENGTH(msg_subj) >= SIZEOF(msg_subj) THEN
- BEGIN;
- WRITELN('**** Warning -- MSG_SUBJ size error');
- WRITELN('Record number # ', no_blk, '(', li,
- ') is msg # ', msg_number);
- WRITELN('MSG_SUBJ = ', msg_subj);
- WRITELN('L = ', LENGTH(msg_subj),
- ' -- MAX = ', SIZEOF(msg_subj));
- IF deleteme THEN GOTO loop;
- END;
-
- END;
-
- (*-------------------------------------------------------------------*)
- (* Read in distribution list *)
- (*-------------------------------------------------------------------*)
-
- IF (mf_fwd_list AND msg_buffer.msg_flag) <> 0 THEN
- BEGIN;
-
- INC(no_blk);
-
- READ(msg_file, msg2_buffer);
-
- WITH dis_p^ DO
- BEGIN;
-
- IF msg_d_no > msg_dist_max THEN
- BEGIN;
- WRITELN('Invalid distribution # -- ', msg_d_no);
- WRITELN('M # = ', msg_buffer.msg_number);
- WRITELN('I = ', i);
- IF deleteme THEN GOTO loop;
- END;
-
- END;
-
- END;
-
- (*-------------------------------------------------------------------*)
- (* Write fix file *)
- (*-------------------------------------------------------------------*)
-
- WRITE(fix_file, msg_buffer);
- IF (mf_fwd_list AND msg_buffer.msg_flag) <> 0 THEN
- WRITE(fix_file, msg2_buffer);
-
- END; (*----- End of loop reading records ------------------------------*)
-
- WRITELN('Processed ', no_blk, ' records.');
-
- CLOSE(msg_file);
-
- CLOSE(fix_file);
-
- IF rename_it THEN
- BEGIN;
-
- ASSIGN(e_file, 'MSG.BAD');
- {$I-}
- ERASE(e_file);
- i := IORESULT;
- {$I+}
-
- RENAME(msg_file, 'MSG.BAD');
- RENAME(fix_file, 'MSG.BB');
-
- WRITELN('The good file is still MSG.BB');
- WRITELN('The bad file has been renamed MSG.BAD');
-
- END;
-
- END.